package org.vincen.springapp.domain.diogenes;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(schema = "diogenes", name = "T_DEPARTMENT")
@Access(AccessType.FIELD)
public class Department implements Serializable {

	private static final long serialVersionUID = -8754881262957512400L;

	@Id
	@Column(name = "dept_id")
	@SequenceGenerator(schema = "diogenes", name = "Dept_gen", sequenceName = "DEPARMENT_SEQ")
	@GeneratedValue(generator = "Dept_gen")
	private Integer deptId;
	@Column(name = "dept_name")
	private String deptName;
	@Column(name = "sup_dept_id")
	private Integer supDeptId;
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name = "T_DEPT_USER", 
	           joinColumns = @JoinColumn(name = "dept_id"), 
	           inverseJoinColumns = @JoinColumn(name = "user_id"))
	private Collection<User> users;

	public Department() {
		super();
	}

	public Department(String deptName, Integer supDeptId) {
		super();
		this.deptName = deptName;
		this.supDeptId = supDeptId;
	}

	public String getDeptName() {
		return deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	public Integer getSupDeptId() {
		return supDeptId;
	}

	public void setSupDeptId(Integer supDeptId) {
		this.supDeptId = supDeptId;
	}

	public Collection<User> getUsers() {
		return users;
	}

	public void setUsers(Collection<User> users) {
		this.users = users;
	}

	public Integer getDeptId() {
		return deptId;
	}

}
